<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class text_file_backend</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Log v2">
<link rel="up" href="../../../sinks.html#header.boost.log.sinks.text_file_backend_hpp" title="Header &lt;boost/log/sinks/text_file_backend.hpp&gt;">
<link rel="prev" href="file/make_collector.html" title="Function template make_collector">
<link rel="next" href="text_ipc_message__idm34474.html" title="Class template text_ipc_message_queue_backend">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="file/make_collector.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../sinks.html#header.boost.log.sinks.text_file_backend_hpp"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="text_ipc_message__idm34474.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.log.sinks.text_file_backend"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class text_file_backend</span></h2>
<p>boost::log::sinks::text_file_backend — An implementation of a text file logging sink backend. </p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../../sinks.html#header.boost.log.sinks.text_file_backend_hpp" title="Header &lt;boost/log/sinks/text_file_backend.hpp&gt;">boost/log/sinks/text_file_backend.hpp</a>&gt;

</span>
<span class="keyword">class</span> <a class="link" href="text_file_backend.html" title="Class text_file_backend">text_file_backend</a> <span class="special">:</span> <span class="keyword">public</span> basic_formatted_sink_backend&lt; char, combine_requirements&lt; synchronized_feeding, flushing &gt;::type &gt;
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">base_type</span><span class="special">::</span><span class="identifier">char_type</span>            <a name="boost.log.sinks.text_file_backend.char_type"></a><span class="identifier">char_type</span><span class="special">;</span>                      <span class="comment">// Character type. </span>
  <span class="keyword">typedef</span> <span class="identifier">base_type</span><span class="special">::</span><span class="identifier">string_type</span>          <a name="boost.log.sinks.text_file_backend.string_type"></a><span class="identifier">string_type</span><span class="special">;</span>                    <span class="comment">// String type to be used as a message text holder. </span>
  <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">char_type</span> <span class="special">&gt;</span> <a name="boost.log.sinks.text_file_backend.stream_type"></a><span class="identifier">stream_type</span><span class="special">;</span>                    <span class="comment">// Stream type. </span>
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>                     <a name="boost.log.sinks.text_file_backend.open_handler_type"></a><span class="identifier">open_handler_type</span><span class="special">;</span>              <span class="comment">// File open handler. </span>
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>                     <a name="boost.log.sinks.text_file_backend.close_handler_type"></a><span class="identifier">close_handler_type</span><span class="special">;</span>             <span class="comment">// File close handler. </span>
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>                     <a name="boost.log.sinks.text_file_backend.time_based_rotati_idm34023"></a><span class="identifier">time_based_rotation_predicate</span><span class="special">;</span>  <span class="comment">// Predicate that defines the time-based condition for file rotation. </span>

  <span class="comment">// <a class="link" href="text_file_backend.html#boost.log.sinks.text_file_backendconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="text_file_backend.html#idm34190-bb"><span class="identifier">text_file_backend</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> ArgsT<span class="special">&gt;</span> <span class="keyword">explicit</span> <a class="link" href="text_file_backend.html#idm34193-bb"><span class="identifier">text_file_backend</span></a><span class="special">(</span><span class="identifier">ArgsT</span><span class="special">...</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="text_file_backend.html#idm34239-bb"><span class="special">~</span><span class="identifier">text_file_backend</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="text_file_backend.html#idm34027-bb">public member functions</a></span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> PathT<span class="special">&gt;</span> <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34028-bb"><span class="identifier">set_file_name_pattern</span></a><span class="special">(</span><span class="identifier">PathT</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> PathT<span class="special">&gt;</span> <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34039-bb"><span class="identifier">set_target_file_name_pattern</span></a><span class="special">(</span><span class="identifier">PathT</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34053-bb"><span class="identifier">set_open_mode</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">openmode</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34062-bb"><span class="identifier">set_file_collector</span></a><span class="special">(</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span> <a class="link" href="file/collector.html" title="Struct collector">file::collector</a> <span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34072-bb"><span class="identifier">set_open_handler</span></a><span class="special">(</span><span class="identifier">open_handler_type</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34081-bb"><span class="identifier">set_close_handler</span></a><span class="special">(</span><span class="identifier">close_handler_type</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34090-bb"><span class="identifier">set_rotation_size</span></a><span class="special">(</span><span class="identifier">uintmax_t</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34101-bb"><span class="identifier">set_time_based_rotation</span></a><span class="special">(</span><span class="identifier">time_based_rotation_predicate</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34112-bb"><span class="identifier">enable_final_rotation</span></a><span class="special">(</span><span class="keyword">bool</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34122-bb"><span class="identifier">auto_flush</span></a><span class="special">(</span><span class="keyword">bool</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34132-bb"><span class="identifier">set_auto_newline_mode</span></a><span class="special">(</span><span class="identifier">auto_newline_mode</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">path</span> <a class="link" href="text_file_backend.html#idm34142-bb"><span class="identifier">get_current_file_name</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">uintmax_t</span> <a class="link" href="text_file_backend.html#idm34148-bb"><span class="identifier">scan_for_files</span></a><span class="special">(</span><span class="identifier">file</span><span class="special">::</span><span class="identifier">scan_method</span> <span class="special">=</span> <span class="identifier">file</span><span class="special">::</span><span class="identifier">scan_matching</span><span class="special">,</span> 
                           <span class="keyword">bool</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34174-bb"><span class="identifier">consume</span></a><span class="special">(</span><span class="identifier">record_view</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">,</span> <span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34182-bb"><span class="identifier">flush</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="text_file_backend.html#idm34186-bb"><span class="identifier">rotate_file</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idm71474"></a><h2>Description</h2>
<p>The sink backend puts formatted log records to a text file. The sink supports file rotation and advanced file control, such as size and file count restriction. </p>
<div class="refsect2">
<a name="idm71477"></a><h3>
<a name="boost.log.sinks.text_file_backendconstruct-copy-destruct"></a><code class="computeroutput">text_file_backend</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="idm34190-bb"></a><span class="identifier">text_file_backend</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Default constructor. The constructed sink backend uses default values of all the parameters. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">...</span> ArgsT<span class="special">&gt;</span> <span class="keyword">explicit</span> <a name="idm34193-bb"></a><span class="identifier">text_file_backend</span><span class="special">(</span><span class="identifier">ArgsT</span><span class="special">...</span> <span class="keyword">const</span> <span class="special">&amp;</span> args<span class="special">)</span><span class="special">;</span></pre>
<p>Constructor. Creates a sink backend with the specified named parameters. The following named parameters are supported:</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">file_name</code> - Specifies the active file name pattern where logs are actually written to. The pattern may contain directory and file name portions, but only the file name may contain placeholders. The backend supports Boost.DateTime placeholders for injecting current time and date into the file name. Also, an additional N placeholder is supported, it will be replaced with an integral increasing file counter. The placeholder may also contain width specification in the printf-compatible form (e.g. %5N). The printed file counter will always be zero-filled. If <code class="computeroutput">file_name</code> is not specified, pattern "%5N.log" will be used. </p></li>
<li class="listitem"><p><code class="computeroutput">target_file_name</code> - Specifies the target file name pattern to use to rename the log file on rotation, before passing it to the file collector. The pattern may contain the same placeholders as the <code class="computeroutput">file_name</code> parameter. By default, no renaming is done, i.e. the written log file keeps its name according to <code class="computeroutput">file_name</code>. </p></li>
<li class="listitem"><p><code class="computeroutput">open_mode</code> - File open mode. The mode should be presented in form of mask compatible to <code class="computeroutput">std::ios_base::openmode</code>. If not specified, <code class="computeroutput">trunc | out</code> will be used. </p></li>
<li class="listitem"><p><code class="computeroutput">rotation_size</code> - Specifies the approximate size, in characters written, of the temporary file upon which the file is passed to the file collector. Note the size does not count any possible character conversions that may take place during writing to the file. If not specified, the file won't be rotated upon reaching any size. </p></li>
<li class="listitem"><p><code class="computeroutput">time_based_rotation</code> - Specifies the predicate for time-based file rotation. No time-based file rotations will be performed, if not specified. </p></li>
<li class="listitem"><p><code class="computeroutput">enable_final_rotation</code> - Specifies a flag, whether or not perform log file rotation on sink backend destruction. By default, is <code class="computeroutput">true</code>. </p></li>
<li class="listitem"><p><code class="computeroutput">auto_flush</code> - Specifies a flag, whether or not to automatically flush the file after each written log record. By default, is <code class="computeroutput">false</code>. </p></li>
<li class="listitem"><p><code class="computeroutput">auto_newline_mode</code> - Specifies automatic trailing newline insertion mode. Must be a value of the <code class="computeroutput">auto_newline_mode</code> enum. By default, is <code class="computeroutput">auto_newline_mode::insert_if_missing</code>.</p></li>
</ul></div>
<p>
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Read the caution note regarding file name pattern in the <code class="computeroutput">sinks::file::collector::scan_for_files</code> documentation. </p></td></tr>
</table></div>
<p>
</p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="idm34239-bb"></a><span class="special">~</span><span class="identifier">text_file_backend</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Destructor </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="idm71558"></a><h3>
<a name="idm34027-bb"></a><code class="computeroutput">text_file_backend</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> PathT<span class="special">&gt;</span> <span class="keyword">void</span> <a name="idm34028-bb"></a><span class="identifier">set_file_name_pattern</span><span class="special">(</span><span class="identifier">PathT</span> <span class="keyword">const</span> <span class="special">&amp;</span> pattern<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the active file name wildcard for the files being written. The wildcard supports date and time injection into the file name.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">pattern</code></span></p></td>
<td><p>The name pattern for the file being written. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> PathT<span class="special">&gt;</span> 
  <span class="keyword">void</span> <a name="idm34039-bb"></a><span class="identifier">set_target_file_name_pattern</span><span class="special">(</span><span class="identifier">PathT</span> <span class="keyword">const</span> <span class="special">&amp;</span> pattern<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the target file name wildcard for the files being rotated. The wildcard supports date and time injection into the file name.</p>
<p>This pattern will be used when the log file is being rotated, to rename the just written log file (which has the name according to the pattern in the <code class="computeroutput">file_name</code> constructor parameter or set by a call to <code class="computeroutput">set_file_name_pattern</code>), just before passing the file to the file collector.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">pattern</code></span></p></td>
<td><p>The name pattern for the file being rotated. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34053-bb"></a><span class="identifier">set_open_mode</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">openmode</span> mode<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the file open mode</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">mode</code></span></p></td>
<td><p>File open mode </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34062-bb"></a><span class="identifier">set_file_collector</span><span class="special">(</span><span class="identifier">shared_ptr</span><span class="special">&lt;</span> <a class="link" href="file/collector.html" title="Struct collector">file::collector</a> <span class="special">&gt;</span> <span class="keyword">const</span> <span class="special">&amp;</span> collector<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the log file collector function. The function is called on file rotation and is being passed the written file name.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">collector</code></span></p></td>
<td><p>The file collector function object </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34072-bb"></a><span class="identifier">set_open_handler</span><span class="special">(</span><span class="identifier">open_handler_type</span> <span class="keyword">const</span> <span class="special">&amp;</span> handler<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets file opening handler. The handler will be called every time the backend opens a new temporary file. The handler may write a header to the opened file in order to maintain file validity.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">handler</code></span></p></td>
<td><p>The file open handler function object </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34081-bb"></a><span class="identifier">set_close_handler</span><span class="special">(</span><span class="identifier">close_handler_type</span> <span class="keyword">const</span> <span class="special">&amp;</span> handler<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets file closing handler. The handler will be called every time the backend closes a temporary file. The handler may write a footer to the opened file in order to maintain file validity.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">handler</code></span></p></td>
<td><p>The file close handler function object </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34090-bb"></a><span class="identifier">set_rotation_size</span><span class="special">(</span><span class="identifier">uintmax_t</span> size<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets maximum file size. When the size is reached, file rotation is performed.</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The size does not count any possible character translations that may happen in the underlying API. This may result in greater actual sizes of the written files.</p></td></tr>
</table></div>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">size</code></span></p></td>
<td><p>The maximum file size, in characters. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34101-bb"></a><span class="identifier">set_time_based_rotation</span><span class="special">(</span><span class="identifier">time_based_rotation_predicate</span> <span class="keyword">const</span> <span class="special">&amp;</span> predicate<span class="special">)</span><span class="special">;</span></pre>
<p>The method sets the predicate that defines the time-based condition for file rotation.</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The rotation always occurs on writing a log record, so the rotation is not strictly bound to the specified condition.</p></td></tr>
</table></div>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">predicate</code></span></p></td>
<td><p>The predicate that defines the time-based condition for file rotation. If empty, no time-based rotation will take place. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34112-bb"></a><span class="identifier">enable_final_rotation</span><span class="special">(</span><span class="keyword">bool</span> enable<span class="special">)</span><span class="special">;</span></pre>
<p>The method allows to enable or disable log file rotation on sink destruction.</p>
<p>By default the sink backend will rotate the log file, if it's been written to, on destruction.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">enable</code></span></p></td>
<td><p>The flag indicates whether the final rotation should be performed. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34122-bb"></a><span class="identifier">auto_flush</span><span class="special">(</span><span class="keyword">bool</span> enable <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span><span class="special">;</span></pre>
<p>Sets the flag to automatically flush write buffers of the file being written after each log record.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">enable</code></span></p></td>
<td><p>The flag indicates whether the automatic buffer flush should be performed. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34132-bb"></a><span class="identifier">set_auto_newline_mode</span><span class="special">(</span><span class="identifier">auto_newline_mode</span> mode<span class="special">)</span><span class="special">;</span></pre>
<p>Selects whether a trailing newline should be automatically inserted after every log record. See <code class="computeroutput">auto_newline_mode</code> description for the possible modes of operation.</p>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">mode</code></span></p></td>
<td><p>The trailing newline insertion mode. </p></td>
</tr></tbody>
</table></div></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">path</span> <a name="idm34142-bb"></a><span class="identifier">get_current_file_name</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Returns:</span></p></td>
<td><p>The name of the currently open log file. If no file is open, returns an empty path. </p></td>
</tr></tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">uintmax_t</span> <a name="idm34148-bb"></a><span class="identifier">scan_for_files</span><span class="special">(</span><span class="identifier">file</span><span class="special">::</span><span class="identifier">scan_method</span> method <span class="special">=</span> <span class="identifier">file</span><span class="special">::</span><span class="identifier">scan_matching</span><span class="special">,</span> 
                         <span class="keyword">bool</span> update_counter <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span><span class="special">;</span></pre>
<p>Performs scanning of the target directory for log files that may have been left from previous runs of the application. The found files are considered by the file collector as if they were rotated.</p>
<p>The file scan can be performed in two ways: either all files in the target directory will be considered as log files, or only those files that satisfy the target file name pattern. See documentation on <code class="computeroutput">sinks::file::collector::scan_for_files</code> for more information.</p>
<p>


</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The method essentially delegates to the same-named function of the file collector. </p></td></tr>
</table></div>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">method</code></span></p></td>
<td><p>File scanning method </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">update_counter</code></span></p></td>
<td><p>If <code class="computeroutput">true</code> and <span class="emphasis"><em>method</em></span> is <code class="computeroutput">scan_matching</code>, the method attempts to update the internal file counter according to the found files. The counter is unaffected otherwise. </p></td>
</tr>
</tbody>
</table></div></td>
</tr>
<tr>
<td><p><span class="term">Requires:</span></p></td>
<td><p>File collector and the proper file name pattern have already been set.</p></td>
</tr>
<tr>
<td><p><span class="term">Returns:</span></p></td>
<td><p>The number of files found.</p></td>
</tr>
</tbody>
</table></div>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34174-bb"></a><span class="identifier">consume</span><span class="special">(</span><span class="identifier">record_view</span> <span class="keyword">const</span> <span class="special">&amp;</span> rec<span class="special">,</span> <span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&amp;</span> formatted_message<span class="special">)</span><span class="special">;</span></pre>
<p>The method writes the message to the sink </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34182-bb"></a><span class="identifier">flush</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>The method flushes the currently open log file </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idm34186-bb"></a><span class="identifier">rotate_file</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>The method rotates the file </p>
</li>
</ol></div>
</div>
</div>
</div>
<div class="copyright-footer">Copyright © 2007-2024 Andrey Semashev<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>).
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="file/make_collector.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../sinks.html#header.boost.log.sinks.text_file_backend_hpp"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="text_ipc_message__idm34474.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
